package com.itheima.dao;

import com.github.pagehelper.Page;
import com.itheima.pojo.CheckGroup;
import com.itheima.pojo.Role;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;

import java.util.HashMap;
import java.util.List;
import java.util.Set;

public interface RoleDao {

    @Select("select r.* from t_role r,t_user_role ur where r.id = ur.role_id and ur.user_id = #{user_id}")
    public Set<Role> findByUserId(Integer userId);

    @Select("select * from t_role")
    List<Role> findAll();

    Page<CheckGroup> findByCondition(String queryString);

    void add(Role role);

    void setRoleAndMenu(HashMap<String, Integer> map);

    void setRoleAndPermission(HashMap<String, Integer> map);

    @Select("select * from t_role where id=#{id}")
    Role findById(Integer id);

    @Select("select menu_id from t_role_menu where role_id=#{id}")
    List<Integer> findMenuIdsByUserId(Integer id);

    @Select("select permission_id from t_role_permission where role_id=#{id}")
    List<Integer> findPermissionIdsByRoleId(Integer id);

    void edit(Role role);

    @Delete("delete from t_role_menu where role_id = #{id}")
    void deleteAssocication4Menu(Integer id);

    @Delete("delete from t_role_permission where role_id = #{id}")
    void deleteAssocication4Permission(Integer id);

    @Select("select count(*) from t_user_role where role_id = #{id}")
    long findCountRoleId(Integer id);

    @Delete("delete from t_role_menu where role_id = #{id}")
    void deleteAssocication1(Integer id);

    @Delete("delete from t_role_permission where role_id = #{id}")
    void deleteAssocication2(Integer id);

    @Delete("delete from t_role where id=#{id}")
    void deleteById(Integer id);
}
